package cc.ok200.api;

import cc.ok200.api.common.StaticHolder;
import cc.ok200.api.repository.UserDao;
import cc.ok200.api.repository.UserTokenDao;
import cc.ok200.api.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Api implements CommandLineRunner {

	@Autowired
	private UserDao userDao;
	
	@Autowired
	private UserTokenDao userTokenDao;

	public static void main(String[] args) {
		SpringApplication.run(Api.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		// 保存DAO到StaticHolder
		StaticHolder.userDao = userDao;
		StaticHolder.userTokenDao = userTokenDao;
		
		// 启动WebSocket服务器
		WebSocketServer.launch();
	}
}
